2 using System
.Collections
;
6 [AddComponentMenu("EZ Effects/Complex Light")]
7 public class ComplexLight
: MonoBehaviour
9 [Header("Fade Properties")]
15 /// A gradient that represents the change in color of the light.
17 public Gradient ColorGradient
;
19 /// How long to fade the light, in seconds.
21 public float FadeTime
;
23 /// Should the light automatically fade when enabled? Useful when used with an EffectImpact or EffectMuzzleFlash.
25 public bool FadeOutOnEnable
;
27 [Header("Flicker Properties")]
29 /// Should this light flicker?
33 /// The range in intensity the light uses while flickering.
35 public Range IntensityRange
;
37 /// How quickly the light should flicker.
39 public float FlickerSpeed
;
42 bool fadeIn
, off
, fading
;
47 randomValue
= Random
.insideUnitCircle
.normalized
;
50 Light
= GetComponentInChildren
<Light
>();
54 Debug
.LogError("LightComplex " + gameObject
.name
+ " does not have a light assigned!");
71 StartCoroutine(fade(FadeTime
));
75 /// Starts a fade in of the light.
76 /// <param name="time">An optional parameter defining how long to fade the light (in seconds).</param>
78 public void FadeIn(float time
= -1)
87 StartCoroutine(fade(time
));
91 /// Starts a fade out of the light.
92 /// <param name="time">An optional parameter defining how long to fade the light (in seconds).</param>
94 public void FadeOut(float time
= -1)
103 StartCoroutine(fade(time
));
106 IEnumerator
fade(float fadeTime
)
111 Light
.enabled
= true;
113 while (timer
< fadeTime
)
115 timer
+= Time
.deltaTime
;
118 Light
.color
= ColorGradient
.Evaluate(1 - (timer
/ fadeTime
));
120 Light
.color
= ColorGradient
.Evaluate(timer
/ fadeTime
);
130 Light
.enabled
= false;
141 float noise
= Mathf
.PerlinNoise(Time
.time
* randomValue
.x
* FlickerSpeed
, Time
.time
* randomValue
.y
* FlickerSpeed
);
142 Light
.intensity
= IntensityRange
.Lerp(noise
);